# coding: utf-8
# 文件名称: pdd_spider.py
# 创建时间: 2021/6/28 12:05

# 使用代理请求,传递 proxies 参数就可以
import requests
import time
import re

daili_url = 'http://t.ipjldl.com/index.php/api/entry?method=proxyServer.generate_api_url&packid=1&fa=0&fetch_key=&groupid=0&qty=1&time=1&pro=&city=&port=1&format=txt&ss=1&css=&dt=1&specialTxt=3&specialJson=&usertype=2'

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54',
    'Cookie':'api_uid=rBQQsGDT8p0yqXGkVSsyAg==; _nano_fp=XpExn0doX5UjXqTxXo_wAIRBer5aDJetLDQuKV4~; dilx=8xlb1_ZSWmiXR2ljWOLsb; msec=1800000; jrpl=GTazOi3TWMIQ6BY3OAH8b23F4PJG7PP2; njrpl=GTazOi3TWMIQ6BY3OAH8b23F4PJG7PP2; ua=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F91.0.4472.114%20Safari%2F537.36%20Edg%2F91.0.864.54; webp=1; PDDAccessToken=W4ZCEA2YPQQN47M2PWPKETB5UIGYHTDLMGT2QL7Q2PR3KRG6ZPIQ111735b; pdd_user_id=5570033875315; pdd_user_uin=RFMS7F4T4CFRZXONF6CH3XIAOA_GEXDA; chat_list_rec_list=chat_list_rec_list_XrHd4y; chat_config=%7B%22host_whitelist%22%3A%5B%22.yangkeduo.com%22%2C%22.pinduoduo.com%22%2C%22.10010.com%2Fqueen%2Ftencent%2Fpinduoduo-fill.html%22%2C%22.ha.10086.cn%2Fpay%2Fcard-sale!toforward.action%22%2C%22wap.ha.10086.cn%22%2C%22m.10010.com%22%5D%7D; pdd_vds=gavLhITaBQfQcLrGhbuEhnlElErQctBNBPYIsETbxPxacaCPsIYnDLDmhPDN',
    'Host':'mobile.pinduoduo.com',
    'Upgrade-Insecure-Requests':'1',
    'Connection':'keep-alive',
    'Cache-Control':'max-age=0',
    'Accept-Language':'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6,zh-TW;q=0.5',
    'Accept-Encoding':'gzip, deflate',
    'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
}

lis = []
def request_pdd(url,proxies):
    response = requests.get(url, headers=headers)
    dicts = response.json()
    datas = dicts['data']
    for data in datas:
        goods_id = data['goods_id']
        price_info = float(data['price_info'])
        if price_info < 0.8:
            print(goods_id)
            lis.append(goods_id)

def main():
    for x in [1,100,200,300,400,500,600,700,800,900]:
        url = f'http://mobile.pinduoduo.com/proxy/api/api/barrow/query?pdduid=5570033875315&app_name=rectab_sim_gyl&' \
              f'support_types=0_1&page_sn=10272&offset={x}&count=100&list_id=4qh66gyooz&dp_list_id=4qh66gyooz_dp'

        daili_ip = requests.get(daili_url).text
        #print(daili_ip)

        proxies = {
            'http': '61.187.243.208:45118'
        }
        request_pdd(url, proxies)
        time.sleep(10)


if __name__ == '__main__':
    main()